package com.sctu.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;
import com.sctu.EMSApp.R;
import com.sctu.bean.RoundBean;

import java.util.List;

/**
 * Created by fll on 2015/12/17.
 */
public class RoundAdapter extends BaseAdapter {

    private List<RoundBean.Results> views;
    private Activity activity;

    public RoundAdapter(List<RoundBean.Results> views,Activity activity){
        this.views = views;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        if (views != null && views.size() > 0){
            return views.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(activity).inflate(R.layout.fragment_scenictour_round_item,null);

        TextView roundID = (TextView) view.findViewById(R.id.round_id);
        TextView roundCharacter = (TextView) view.findViewById(R.id.round_charac);
        TextView roundStart = (TextView) view.findViewById(R.id.round_start);
        TextView roundEnd = (TextView) view.findViewById(R.id.round_end);
        RatingBar ratingBar = (RatingBar) view.findViewById(R.id.round_ratingbar);

        roundID.setText(views.get(position).getOrder());
        roundCharacter.setText("("+views.get(position).getCharacteristic()+")");
        roundStart.setText(views.get(position).getOrigin());
        roundEnd.setText(views.get(position).getDestination());
        ratingBar.setRating(Float.parseFloat(views.get(position).getRecommendation()));

        return view;
    }
}
